using UnityEngine;
using System.Collections;

public class MonsterGenerator : MonoBehaviour {

	// We'll almost certainly need a monster pool.

	public GameObject monsterPrefab;
	public float spawnDelay = 5f;
	public float spawnCooldown = 0;
	public int monsterPerSpawn = 1;
	public int numSpawns = 5;	// Self-Destruct after this many spawns

	float rotSpeed = -180f;

	void Start() {
		Health h = GetComponent<Health>();
		h.initHPs *= GameManager.Instance.DifficultyExponential();
		h.hps = h.initHPs;
	}

	// Update is called once per frame
	void Update () {
		spawnCooldown -= Time.deltaTime;

		if(spawnCooldown <= 0) {
			spawnCooldown = spawnDelay;
			DoSpawn();
		}

		this.transform.Rotate( new Vector3(0, 0, rotSpeed * Time.deltaTime) );
	}

	void DoSpawn() {
		for(int i = 0; i < monsterPerSpawn; i++) {
			Instantiate(monsterPrefab, transform.position, transform.rotation);
		}

		if(numSpawns > 0) {
			numSpawns--;

			if(numSpawns==0) {
				// TODO:  Fun blink-out effect
				Destroy(gameObject);
			}
		}
	}

}
